package com.hwd.srb.core.controller.api;


import com.alibaba.excel.EasyExcel;
import com.hwd.srb.common.constant.Constants;
import com.hwd.srb.common.constant.DictConstants;
import com.hwd.srb.common.exception.Assert;
import com.hwd.srb.common.exception.BusinessException;
import com.hwd.srb.common.result.R;
import com.hwd.srb.common.result.ResponseEnum;
import com.hwd.srb.core.pojo.dto.ExcelDictDTO;
import com.hwd.srb.core.pojo.entity.Dict;
import com.hwd.srb.core.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author 黄伟东/Victor
 * @since 2022-03-14
 */
@RestController
@RequestMapping("/api/core/dict")
@Api(tags = "数据字典接口")
public class ApiDictController {

    @Resource
    private DictService dictService;

    /**
     * 根据dictCode查询字典集合
     *
     * @param dictCode dictCode
     * @return com.hwd.srb.common.result.R
     */
    @GetMapping("/findByDictCode/{dictCode}")
    @ApiOperation("根据dictCode查询字典集合")
    public R listByParentId(@ApiParam(value = "字典表的dictCode", required = true) @PathVariable("dictCode") String dictCode) {

        List<Dict> dictList = dictService.findByDictCode(dictCode);

        // 断言数据字典列表不为空
        Assert.notNull(dictList, DictConstants.LIST_DICT_ERROR);

        return R.ok().message(DictConstants.LIST_DICT_SUCCESS).data(DictConstants.DICT_LISTS_KEY, dictList);
    }


}

